package nah;

import static org.junit.Assert.assertTrue;
import nah.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.ITurnSnapshot;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that KillaRobot does not
 * lose all its energy and becomes disabled.
 *  
 * @author Nathaniel Ashe
 * 
 */
public class TestKillaRobotEnergy extends RobotTestBed {
  ITurnSnapshot snapshot;
  boolean energy = true;

  /**
   * Specifies that Crazy and KillaRobot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,nah.KillaRobot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if KillaRobot loses all its energy.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    int score = 0;
    snapshot = event.getTurnSnapshot();

    for (IRobotSnapshot energy : snapshot.getRobots()) {
      // Gets the energy of KillaRobot
      score = (int) energy.getEnergy();
    }

    // Energy becomes false if KillaRobot's energy became 0 in some round.
    if (score == 0) {
      energy = false;
    }

  }

  /**
   * The actual test, which asserts that KillaRobot does not lose all its energy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Damage", energy);
  }
}
